<template>
  <Card title="科室管理 - 编辑">
    <Card :bordered="false">
      <Button type="primary" @click="show" >添加</Button>
    </Card>
    <Table width="550" border stripe ref="selection" size="small" :columns="columns" :data="nowData">
      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" size="small" style="margin-right: 5px" @click="show(row)">编辑</Button>
        <Button type="error" size="small" @click="remove(row)">删除</Button>
        <Modal
          v-model="modal1"
          title="提示"
          @on-ok="okDel"
          @on-cancel="cancel">
          <p>确定要删除此科室吗?删除后将不能恢复</p>
        </Modal>
      </template>
    </Table>
    <Page :total="dataCount" :page-size="pagingCondition.size" @on-change="changePage"
          @on-page-size-change="_nowPageSize"
          show-total show-sizer show-elevator/>
  </Card>
</template>

<script>
export default {
  name: 'venues-category',
  data () {
    return {
      delRow: {},
      cuVenuesCategory: {
        cuVenuesCategoryId: null,
        cuVenuesCategoryName: ''
      },
      dataCount: 0,
      pagingCondition: {
        size: 10,
        current: 1
      },
      modal1: false,
      columns: [
        {
          title: '序号',
          key: 'cuVenuesCategoryId'
        },
        {
          title: '编号',
          key: 'cuVenuesCategoryName'
        },
        {
          title: '操作',
          slot: 'action',
          width: 150,
          align: 'center'
        }
      ],
      nowData: []

    }
  },
  methods: {
    okDel () {
      (this.delRow)
      this.$axios_supermall.post('/cu-venues-category/deleteId', this.delRow.cuVenuesCategoryId).then(resp => {
        if (resp.data.code == 0) {
          this.$Message.info('删除成功')
          this.query()
        } else {
          this.$Message.info(resp.data.msg)
        }
      })
    },
    remove (row) {
      this.delRow = row
      this.modal1 = true
    },
    cancel () {
      this.$Message.info('取消删除')
    },
    show (row) {
      this.cuVenuesCategory = row
      let url = 'updateOne'
      if (this.cuVenuesCategory.cuVenuesCategoryName == undefined) {
        url = 'saveOne'
      }

      let dateRow = null
      this.$Modal.confirm({
        title: '编辑',
        onOk: async () => {
          if (this.cuVenuesCategory.cuVenuesCategoryName == '') {
            this.$Message.error('科室名称不能为空')
            return
          }
          this.cuVenuesCategory.cuVenuesCategoryName = dateRow

          this.$axios_supermall.post('/cu-venues-category/' + url, this.cuVenuesCategory).then(resp => {
            if (resp.data.code == 0) {
              this.$Message.success(resp.data.msg)
            } else {
              this.$Message.error(resp.data.msg)
            }
            this.query()
          })
        },
        render: (h) => {
          return h('Input', {
            props: {
              value: this.cuVenuesCategory.cuVenuesCategoryName,
              autofocus: true,
              placeholder: ''
            },
            on: {
              input: (val) => {
                dateRow = val
              }
            }

          })
        }

      })
    },

    changePage (index) {
      this.pagingCondition.current = index
      this.query()
    },
    _nowPageSize (index) {
      // 实时获取当前需要显示的条数
      this.pagingCondition.size = index
    },
    query () {
      this.$Loading.start()
      this.$axios_supermall.post('/cu-venues-category/queryPage', this.pagingCondition).then(resp => {
        if (resp.data.code == 0) {
          let data = resp.data.data
          this.nowData = data.records
          this.pagingCondition.current = data.current
          this.pagingCondition.size = data.size
          this.dataCount = data.total
        }
        this.$Loading.finish()
      }).catch(() => {
        this.$Loading.error()
      })
    }
  },
  mounted () {
    this.query()
  }
}
</script>

<style scoped>

</style>
